//
//  YPAgainEmailCertificateViewController.m
//  ChengHuiTong
//
//  Created by 张无忌 on 16/4/11.
//  Copyright © 2016年 张文权. All rights reserved.
//

#import "YPAgainEmailCertificateViewController.h"

@interface YPAgainEmailCertificateViewController ()<UITextFieldDelegate>{
    
    
    UIView *_notEmailCertificateView;
    UITextField * _emailTextField;

}

@end

@implementation YPAgainEmailCertificateViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"邮箱认证";

    [self CreatNotEmailCertificateView];
    

    
}
//初次认证邮箱的时候
- (void)CreatNotEmailCertificateView{
    
    
    _notEmailCertificateView = [[UIView alloc]initWithFrame:self.view.frame];
    _notEmailCertificateView.backgroundColor = UIColorFromRGB(0xf5f5f5);
    
    [self.view addSubview:_notEmailCertificateView];
    
    UILabel * warnLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20)];
    warnLabel.text = @"    提醒：一旦邮箱通过认证将不能修改。";
    warnLabel.backgroundColor = UIColorFromRGB(0xe0e0e0);
    warnLabel.textColor = UIColorFromRGB(0x929292);
    warnLabel.font = [UIFont systemFontOfSize:13];
    [_notEmailCertificateView addSubview:warnLabel];
    
    
    UIView * emailView = [[UIView alloc]initWithFrame:CGRectMake(0, warnLabel.bottom+10, SCREEN_WIDTH, 60)];
    emailView.backgroundColor = [UIColor whiteColor];
    [_notEmailCertificateView addSubview:emailView];
    
    
    UILabel * emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 40, 60)];
    //    emailLabel.backgroundColor = [UIColor orangeColor];
    emailLabel.text = @"邮箱";
    [emailView addSubview:emailLabel];
    
    
    _emailTextField = [[UITextField alloc]initWithFrame:CGRectMake(emailLabel.right+20, 0, SCREEN_WIDTH-15-40-20-15, 60)];
    _emailTextField.delegate = self;
    //    _emailTextField.backgroundColor = [UIColor cyanColor];
    _emailTextField.placeholder = @"请输入邮箱地址";
    _emailTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _emailTextField.returnKeyType = UIReturnKeyDone;
    [emailView addSubview:_emailTextField];
    
    
    
    UIButton * submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    submitButton.frame = CGRectMake(15, emailView.bottom+50, SCREEN_WIDTH-30, 44);
    submitButton.backgroundColor =  kColor_AppNavColor;
    [submitButton setTitle:@"确定提交" forState:0];
    [submitButton setTitleColor:[UIColor whiteColor] forState:0];
    submitButton.layer.cornerRadius =5;
    submitButton.clipsToBounds = YES;
    [submitButton addTarget:self action:@selector(submitButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_notEmailCertificateView addSubview:submitButton];
    
    
    
    
    
    
}
- (void)submitButtonClick{
    
    YPEmailCertificateBin * bin = [[YPEmailCertificateBin alloc]init];
    bin.token=[YPShareAccountInfo shareAccountInfo].token;
    bin.email= _emailTextField.text;
    
    
    [YPHttpRequestMethod sendAsyRequestURL:CMD_EMAIL_VERIFY withData:[bin dictionaryValue] withCompletionBlock:^(NSDictionary *responseDictionary) {
        
        NSLog(@"发起邮箱认证请求%@",responseDictionary);
        
        if ([responseDictionary[@"status"] intValue]==0) {
            
            [self.navigationController popToRootViewControllerAnimated:YES];
            
        }else if ([responseDictionary[@"status"] intValue]==1202){
            
            [YRProgressHUD autoShowHUDAddedTo:self.view withText:@"token不匹配"];
            
        }else if ([responseDictionary[@"status"] intValue]==1402){
            
            [YRProgressHUD autoShowHUDAddedTo:self.view withText:@"邮箱地址无效"];
            
        }else if ([responseDictionary[@"status"] intValue]==1403){
            
            [YRProgressHUD autoShowHUDAddedTo:self.view withText:@"邮箱地址已被使用"];
            
            
        }else if ([responseDictionary[@"status"] intValue]==1404){
            
            [YRProgressHUD autoShowHUDAddedTo:self.view withText:@"发送邮件请求太频繁（限制60秒）"];
            
            
        }else if ([responseDictionary[@"status"] intValue]==9000){
            
            [YRProgressHUD autoShowHUDAddedTo:self.view withText:@"服务器繁忙"];
            
        }
        
        
        
    } withFailedBlock:^(NSError *error) {
        
        
    } withIndicator:YES atView:self.view];
    
    
}
#pragma mark -textfield
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [self.view endEditing:YES];
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
